package com.example.demo.controller;

import com.example.demo.api.CarStation;
import com.example.demo.api.CarUser;
import com.example.demo.interceptors.Scopelevel;
import com.example.demo.respository.CarRepository;
import com.example.demo.respository.UserRepository;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "车位信息接口")
@RestController

public class ParkingService {
    @Autowired
    private CarRepository carRepository ;
    @Autowired
    private UserRepository userRepository ;

    @RequestMapping("/findAll")
    @ApiOperation(value = "获取车位当前信息",notes = "返回所有的车位是否被占用")
    public List<CarStation> findAll() {
        return carRepository.findAll() ;
    }



    @RequestMapping("/findAll1")
    @ApiOperation(value = "获取车位当前信息2",notes = "返回所有的车位是否被占用")
    @Scopelevel(Value = 1)
    public List<CarUser> findAll1() {
        return userRepository.findAll() ;
    }


    @RequestMapping(value="/updateCarON",method= RequestMethod.POST)
    @ApiOperation(value = "更改车位信息-设为空闲",notes = "设为空闲")
    public boolean updateCarON(@RequestParam(value ="PKcode")String PKcode ){

        return carRepository.updateon(PKcode) ;
    }

    @RequestMapping(value="/updateCarOff",method= RequestMethod.POST)
    @ApiOperation(value = "更改车位信息-设为占用",notes = "设为占用")
    public boolean updateCarOff(@RequestParam(value ="PKcode")String PKcode ){

        return carRepository.updateoff(PKcode) ;
    }

    @RequestMapping(value="/QuaryStation",method= RequestMethod.POST)
    public CarStation QuaryStation (@RequestParam(value ="PKcode")String PKcode ){
        return carRepository.selectPk(PKcode);
    }
}
